Ext.define('CheckMemberView', {
	extend : 'Ext.panel.Panel',
	id : 'CheckMemberView',
	title : '审题组成员设置',
	region : 'center',
	layout : 'border',
	iconCls: 'menu-cusLinkman',

	initComponent : function() {
		this.topbar = new Ext.Toolbar({
					items : [{
								iconCls : 'btn-add',
								text : '添加审题教师',
								xtype : 'button',
								scope : this,
								handler : this.addTeacher
							}, {
								iconCls : 'btn-del',
								text : '删除审题教师',
								xtype : 'button',
								scope : this,
								handler : this.removeTeacher
							}, '-', {
								iconCls : 'btn-mail_recipient',
								text : '指派题目',
								xtype : 'button',
								scope : this,
								handler : this.giveSubject
							}]
				});

		this.gridPanel = new KE.GridPanel({
			region : 'center',
			tbar : this.topbar,
			id : 'CheckMemberGrid',
			url : __ctxPath + "/byxt/listMember.do",
			fields : ['oid', 'subjectNames', 'subjectIds', {
								name : 'member.fullname',
								mapping : 'member.fullname'
							}],
			columns : [{
						header : 'ID',
						dataIndex : 'oid',
						hidden : true
					}, {
						header : '审题组成员',
						dataIndex : 'member.fullname'
					}, {
						header : '审题数量',
						dataIndex : 'subjectIds',
						flex: 0.5,
						renderer: function(v) {
							if(v) {
								return v.split(',').length;
							} else {
								return 0;
							}
						}
					}, {
						header : '题目',
						dataIndex : 'subjectNames',
						flex: 6
					}]
		});

		this.items = [this.gridPanel];
		this.callParent();
		this.gridPanel.on('rowdblclick', this.rowClick);
	},
	rowClick: function(grid, rec) {
		var me = this;
		SubjectSelector.getView(
				function(ids, names) {
					$postAjax({
						scope: this,
						url: __ctxPath + '/byxt/addSubjectMember.do',
						params: {
							oid: rec.data.oid,
							subjectIds: ids,
							subjectNames: names
						},
						callback: function() {
							me.gridPanel.getStore().reload();
						}
					});
				}, false, rec.data.subjectIds).show();		
	},
	// 增加评审教师
	addTeacher : function() {
		var me = this;
		AppUserSelector.getView(
				function(ids, names) {
					$postAjax({
						scope: this,
						url: __ctxPath + '/byxt/addTeachersMember.do',
						params: {
							userIds: ids
						},
						callback: function() {
							me.gridPanel.getStore().reload();
						}
					});
				}, false, 0, '1,2').show();		
	},
	// 删除评审教师
	removeRs : function(id) {
		$postDel({
			url : __ctxPath + '/byxt/multiDelMember.do',
			ids : id,
			grid : this.gridPanel
		});
	},
	// 把选中ID删除
	removeTeacher : function() {
		$delGridRs({
			url : __ctxPath + '/byxt/multiDelMember.do',
			grid : this.gridPanel,
			idName : 'oid'
		});
	},
	// 指派题目
	giveSubject: function() {
		var rec = $selectOne(this.gridPanel);
		if(!rec) return;		
		var me = this;
		SubjectSelector.getView(
				function(ids, names) {
					$postAjax({
						scope: this,
						url: __ctxPath + '/byxt/addSubjectMember.do',
						params: {
							oid: rec.oid,
							subjectIds: ids,
							subjectNames: names
						},
						callback: function() {
							me.gridPanel.getStore().reload();
						}
					});
				}, false, rec.subjectIds).show();		
	}

});
